﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using BuildARoute.Web.Models;
using BuildARoute.Web.Services;

namespace BuildARoute.Views
{
    public partial class EditStopWindow : ChildWindow
    {
        
        public EditStopWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(EditStopWindow_Loaded);
        }

        void EditStopWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IEditableObject stop = (IEditableObject)this.DataContext;
            
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            IEditableObject stop = (IEditableObject)this.DataContext;
            stop.EndEdit();
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            IEditableObject stop = (IEditableObject)this.DataContext;
            stop.CancelEdit();
            this.DialogResult = false;
        }

        private void languageDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void addPOIButton_Click(object sender, RoutedEventArgs e)
        {
            var poi = new POI();
            poi.POIID = new Guid();
            poi.DateCreated = DateTime.Now;
            poi.LastEdit = DateTime.Now;
            poi.Author = (string)WebContext.Current.User.GetIdentity();


            var poiEditWindow = new EditPOIWindow();
            poiEditWindow.DataContext = poi;
            poiEditWindow.Show();


        }
    }
}

